package com.strato.mvc.api.v1_0_0.model;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

import org.osgi.framework.Bundle;

import com.strato.mvc.api.v1_0_0.view.View;
import com.strato.mvc.api.v1_0_0.view.ViewName;
import com.strato.mvc.api.v1_0_0.view.ViewResolver;

public class ModelAndView {
	
	private Map<Object,Object> model=new HashMap<Object,Object>();
	
	private ViewName viewName;
	
	private View view;

	private WeakReference<Bundle> bundleRef;
	
	public Map<Object,Object> getModel() {
		return model;
	}

	public void setModel(Map<Object,Object> model) {
		this.model = model;
	}

	public ViewName getViewName() {
		return viewName;
	}

	public void setViewName(ViewName viewName) {
		this.viewName = viewName;
	}

	public void setViewName(String viewName) {
		this.viewName = ViewResolver.parseViewName(viewName);
	}

	public View getView() {
		return view;
	}

	public void setView(View view) {
		this.view = view;
	}
	
	public void setInvokingBundle(Bundle bundle){
		this.bundleRef=new WeakReference<Bundle>(bundle);
	}
	
	public Bundle getInvokingBundle(){
		if(bundleRef==null){
			return null;
		}
		return bundleRef.get();
	}
}
